﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;

namespace LED_Tester
{
    public partial class frmL1 : Form
    {
        public frmL1()
        {
            InitializeComponent();
        }

        #region 变量声明

        private int step = 250;
        private double yMin = 0;
        private double yMax = 7000;
        private LineItem[] litData;
        private PointPairList[] pplData;
        private Color[] lineColor = new Color[12] { Color.Red, Color.Green, Color.Blue, Color.Purple, Color.OrangeRed,
            Color.Aqua, Color.Yellow, Color.RoyalBlue, Color.RosyBrown, Color.Violet, Color.Sienna, Color.Firebrick };

        private double gammaSample;
        private double gammaRange;
        private double thetaDegree;

        private double[] luxData;

        private double[][] lux2DData = new double[12][];

        public double GammaSample
        {
            get { return gammaSample; }
            set { gammaSample = value; }
        }
        public double GammaRange
        {
            get { return gammaRange; }
            set { gammaRange = value; }
        }
        public double ThetaDegree
        {
            get { return thetaDegree; }
            set { thetaDegree = value; }
        }

        public double[] LuxData
        {
            get { return luxData; }
            set { luxData = value; }
        }

        #endregion

        #region 功能函数

        private void initailize()
        {
            #region 初始化数据

            litData = new LineItem[12];
            pplData = new PointPairList[12];

            for (int i = 0; i < 12; i++)
            {
                pplData[i] = new PointPairList();
                litData[i] = new LineItem("");
                litData[i] = zedPolar.GraphPane.AddCurve("", pplData[i], lineColor[i], SymbolType.None);
                litData[i].Line.IsSmooth = true;
            }


            #endregion

            #region 初始化图像

            zedPolar.GraphPane.Fill = new Fill(Color.Black);
            zedPolar.GraphPane.Chart.Fill.Type = FillType.None;
            zedPolar.GraphPane.Title.Text = "";
            zedPolar.GraphPane.XAxis.Title.Text = "";
            zedPolar.GraphPane.YAxis.Title.Text = "";

            zedPolar.GraphPane.YAxis.Color = Color.White;
            zedPolar.GraphPane.XAxis.Color = Color.White;
            zedPolar.GraphPane.Y2Axis.Color = Color.White;
            zedPolar.GraphPane.X2Axis.Color = Color.White;

            zedPolar.GraphPane.XAxis.IsVisible = false;
            zedPolar.GraphPane.YAxis.IsVisible = false;
            zedPolar.GraphPane.X2Axis.IsVisible = false;
            zedPolar.GraphPane.Y2Axis.IsVisible = false;
            zedPolar.GraphPane.YAxis.MajorGrid.IsZeroLine = false;
            zedPolar.GraphPane.Chart.Border.IsVisible = false;

            zedPolar.GraphPane.XAxis.Scale.MajorStepAuto = false;
            zedPolar.GraphPane.YAxis.Scale.MajorStepAuto = false;
            zedPolar.GraphPane.XAxis.Scale.Min = -1100;
            zedPolar.GraphPane.XAxis.Scale.Max = 1100;
            zedPolar.GraphPane.YAxis.Scale.Min = -1350;
            zedPolar.GraphPane.YAxis.Scale.Max = 1350;
            zedPolar.GraphPane.XAxis.Scale.MajorStep = 250;
            zedPolar.GraphPane.YAxis.Scale.MajorStep = 250;
            zedPolar.GraphPane.YAxis.Scale.IsSkipFirstLabel = true;
            zedPolar.GraphPane.YAxis.Scale.IsReverse = true;
            zedPolar.GraphPane.XAxis.Scale.IsReverse = true;

            zedPolar.IsShowContextMenu = false;
            zedPolar.IsEnableHZoom = false;
            zedPolar.IsEnableVZoom = false;

            #endregion

            #region 画边框

            PointPairList pplSouth = new PointPairList();
            pplSouth.Add(-4 * step, 5 * step);
            pplSouth.Add(4 * step, 5 * step);
            LineItem litSouth = zedPolar.GraphPane.AddCurve("", pplSouth, Color.White, SymbolType.None);
            litSouth.Line.Width = 2.0f;

            PointPairList pplNorth = new PointPairList();
            pplNorth.Add(-4 * step, -5 * step);
            pplNorth.Add(4 * step, -5 * step);
            LineItem litNorth = zedPolar.GraphPane.AddCurve("", pplNorth, Color.White, SymbolType.None);
            litNorth.Line.Width = 2.0f;

            PointPairList pplWest = new PointPairList();
            pplWest.Add(4 * step, -5 * step);
            pplWest.Add(4 * step, 5 * step);
            LineItem litWest = zedPolar.GraphPane.AddCurve("", pplWest, Color.White, SymbolType.None);
            litWest.Line.Width = 2.0f;

            PointPairList pplEast = new PointPairList();
            pplEast.Add(-4 * step, -5 * step);
            pplEast.Add(-4 * step, 5 * step);
            LineItem iltEast = zedPolar.GraphPane.AddCurve("", pplEast, Color.White, SymbolType.None);
            iltEast.Line.Width = 2.0f;

            PointPairList pplXAsxi = new PointPairList();
            pplXAsxi.Add(-4 * step, 0);
            pplXAsxi.Add(4 * step, 0);
            LineItem litXAsxi = zedPolar.GraphPane.AddCurve("", pplXAsxi, Color.White, SymbolType.None);

            PointPairList pplYAsxi = new PointPairList();
            pplYAsxi.Add(0, -5 * step);
            pplYAsxi.Add(0, 5 * step);
            LineItem litYAxi = zedPolar.GraphPane.AddCurve("", pplYAsxi, Color.White, SymbolType.None);

            #endregion

            #region 画圆弧

            double x, y;

            PointPairList pplArc0 = new PointPairList();
            PointPairList pplArc1 = new PointPairList();
            PointPairList pplArc2 = new PointPairList();
            PointPairList pplArc3 = new PointPairList();
            PointPairList pplArc4 = new PointPairList();
            PointPairList pplArc5 = new PointPairList();

            for (int j = -90; j < 270; j++)
            {
                x = step * Math.Cos(Math.PI * j / 180);
                y = step * Math.Sin(Math.PI * j / 180);

                pplArc0.Add(x, y);
                pplArc1.Add(2 * x, 2 * y);
                pplArc2.Add(3 * x, 3 * y);
                pplArc3.Add(4 * x, 4 * y);

                if (5 * x < -4 * step || 5 * x > 4 * step)
                {
                    continue;
                }

                pplArc4.Add(5 * x, 5 * y);

                if (6 * x < -4 * step || 6 * x > 4 * step || 6 * y > 5 * step + 8.0057f || 6 * y < -2 * step)
                {
                    continue;
                }

                pplArc5.Add(6 * x, 6 * y);
            }

            LineItem litArc0 = zedPolar.GraphPane.AddCurve("", pplArc0, Color.White, SymbolType.None);
            LineItem litArc1 = zedPolar.GraphPane.AddCurve("", pplArc1, Color.White, SymbolType.None);
            LineItem litArc2 = zedPolar.GraphPane.AddCurve("", pplArc2, Color.White, SymbolType.None);
            LineItem litArc3 = zedPolar.GraphPane.AddCurve("", pplArc3, Color.White, SymbolType.None);
            LineItem litArc4 = zedPolar.GraphPane.AddCurve("", pplArc4, Color.White, SymbolType.None);
            LineItem litArc5 = zedPolar.GraphPane.AddCurve("", pplArc5, Color.White, SymbolType.None);

            #endregion

            #region 画射线

            PointPairList pplRay0 = new PointPairList(); //15°
            PointPairList pplRay1 = new PointPairList(); //30°
            PointPairList pplRay2 = new PointPairList(); //45°
            PointPairList pplRay3 = new PointPairList(); //60°
            PointPairList pplRay4 = new PointPairList(); //75°
            PointPairList pplRay5 = new PointPairList(); //-15°
            PointPairList pplRay6 = new PointPairList(); //-30°
            PointPairList pplRay7 = new PointPairList(); //-45°
            PointPairList pplRay8 = new PointPairList(); //-60°
            PointPairList pplRay9 = new PointPairList(); //-75°
            PointPairList pplRay10 = new PointPairList(); //105°
            PointPairList pplRay11 = new PointPairList(); //120°
            PointPairList pplRay12 = new PointPairList(); //135°
            PointPairList pplRay13 = new PointPairList(); //150°
            PointPairList pplRay14 = new PointPairList(); //165°
            PointPairList pplRay15 = new PointPairList(); //-105°
            PointPairList pplRay16 = new PointPairList(); //-120°
            PointPairList pplRay17 = new PointPairList(); //-135°
            PointPairList pplRay18 = new PointPairList(); //-150°
            PointPairList pplRay19 = new PointPairList(); //-165°

            double[,] intersection = new double[14, 2];
            // 15°
            for (y = step * Math.Cos(Math.PI / 180 * 15); y <= 5 * step; y += 1)
            {
                x = y * Math.Tan(Math.PI / 180 * 15);
                if (y > 5 * step - 1)
                {
                    intersection[0, 0] = x;
                    intersection[0, 1] = y;
                }
                pplRay0.Add(x, y);

            }
            // 30°
            for (y = step * Math.Cos(Math.PI / 6); y <= 5 * step; y += 1)
            {
                x = y * Math.Tan(Math.PI / 6);
                if (y > 5 * step - 1)
                {
                    intersection[1, 0] = x;
                    intersection[1, 1] = y;
                }
                pplRay1.Add(x, y);
            }
            // 45°
            for (y = step * Math.Cos(Math.PI / 4); y <= 4 * step; y += 1)
            {
                x = y * Math.Tan(Math.PI / 4);
                if (x > 4 * step - 1)
                {
                    intersection[2, 0] = x;
                    intersection[2, 1] = y;
                }
                pplRay2.Add(x, y);
            }
            // 60°
            for (y = step * Math.Cos(Math.PI / 3); y <= 4 * step / Math.Sqrt(3); y += 1)
            {
                x = y * Math.Tan(Math.PI / 3);
                if (x > 4 * step - 1)
                {
                    intersection[3, 0] = x;
                    intersection[3, 1] = y;
                }
                pplRay3.Add(x, y);
            }
            // 75°
            for (y = step * Math.Cos(Math.PI / 180 * 75); y <= 4 * step / (2 + Math.Sqrt(3)); y += 1)
            {
                x = y * Math.Tan(Math.PI / 180 * 75);
                if (x > 4 * step - 1)
                {
                    intersection[4, 0] = x;
                    intersection[4, 1] = y;
                }
                pplRay4.Add(x, y);
            }
            // -15°
            for (y = step * Math.Cos(Math.PI / 180 * 15); y <= 5 * step; y += 1)
            {
                x = y * Math.Tan(-Math.PI / 180 * 15);
                if (y > 5 * step - 1)
                {
                    intersection[5, 0] = x;
                    intersection[5, 1] = y;
                }
                pplRay5.Add(x, y);
            }
            // -30°
            for (y = step * Math.Cos(Math.PI / 6); y <= 5 * step; y += 1)
            {
                x = y * Math.Tan(-Math.PI / 6);
                if (y > 5 * step - 1)
                {
                    intersection[6, 0] = x;
                    intersection[6, 1] = y;
                }
                pplRay6.Add(x, y);
            }
            // -45°
            for (y = step * Math.Cos(Math.PI / 4); y <= 4 * step; y += 1)
            {
                x = y * Math.Tan(-Math.PI / 4);
                if (x < -4 * step + 1)
                {
                    intersection[7, 0] = x;
                    intersection[7, 1] = y;
                }
                pplRay7.Add(x, y);
            }
            // -60°
            for (y = step * Math.Cos(Math.PI / 3); y <= 4 * step / Math.Sqrt(3); y += 1)
            {
                x = y * Math.Tan(-Math.PI / 3);
                if (x < -4 * step + 1)
                {
                    intersection[8, 0] = x;
                    intersection[8, 1] = y;
                }
                pplRay8.Add(x, y);
            }
            // -75°
            for (y = step * Math.Cos(Math.PI / 180 * 75); y <= 4 * step / (2 + Math.Sqrt(3)); y += 1)
            {
                x = y * Math.Tan(-Math.PI / 180 * 75);
                if (x < -4 * step + 1)
                {
                    intersection[9, 0] = x;
                    intersection[9, 1] = y;
                }
                pplRay9.Add(x, y);
            }
            // 105°
            for (x = step * Math.Cos(Math.PI / 180 * 15); x <= 1000; x += 1)
            {
                y = -x * Math.Tan(Math.PI / 180 * 15);
                if (y < -step + 1)
                {
                    intersection[10, 0] = x;
                    intersection[10, 1] = y;
                }
                pplRay10.Add(x, y);
            }
            // 120°
            for (x = step * Math.Cos(Math.PI / 6); x <= 1000; x += 1)
            {
                y = -x * Math.Tan(Math.PI / 6);
                if (y < -step + 1)
                {
                    intersection[11, 0] = x;
                    intersection[11, 1] = y;
                }
                pplRay11.Add(x, y);
            }
            // 135°
            for (x = step * Math.Cos(Math.PI / 4); x <= 4 * step; x += 1)
            {
                y = -x * Math.Tan(Math.PI / 4);
                pplRay12.Add(x, y);
            }
            // 150°
            for (x = step * Math.Cos(Math.PI / 3); x <= 5 * step / Math.Sqrt(3); x += 1)
            {
                y = -x * Math.Tan(Math.PI / 3);
                pplRay13.Add(x, y);
            }
            // 165°
            for (x = step * Math.Cos(Math.PI / 180 * 75); x <= 5 * step / (2 + Math.Sqrt(3)); x += 1)
            {
                y = -x * Math.Tan(Math.PI / 180 * 75);
                pplRay14.Add(x, y);
            }
            // -105°
            for (x = -step * Math.Cos(Math.PI / 180 * 15); x >= -1000; x -= 1)
            {
                y = x * Math.Tan(Math.PI / 180 * 15);
                if (y < -step + 1)
                {
                    intersection[12, 0] = x;
                    intersection[12, 1] = y;
                }
                pplRay15.Add(x, y);
            }
            // -120°
            for (x = -step * Math.Cos(Math.PI / 6); x >= -1000; x -= 1)
            {
                y = x * Math.Tan(Math.PI / 6);
                if (y < -step + 1)
                {
                    intersection[13, 0] = x;
                    intersection[13, 1] = y;
                }
                pplRay16.Add(x, y);
            }
            // -135°
            for (x = -step * Math.Cos(Math.PI / 4); x >= -4 * step; x -= 1)
            {
                y = x * Math.Tan(Math.PI / 4);
                pplRay17.Add(x, y);
            }
            // -150°
            for (x = -step * Math.Cos(Math.PI / 3); x >= -5 * step / Math.Sqrt(3); x -= 1)
            {
                y = x * Math.Tan(Math.PI / 3);
                pplRay18.Add(x, y);
            }
            // -165°
            for (x = -step * Math.Cos(Math.PI / 180 * 75); x >= -5 * step / (2 + Math.Sqrt(3)); x -= 1)
            {
                y = x * Math.Tan(Math.PI / 180 * 75);
                pplRay19.Add(x, y);
            }

            LineItem litRay0 = zedPolar.GraphPane.AddCurve("", pplRay0, Color.White, SymbolType.None);
            LineItem litRay1 = zedPolar.GraphPane.AddCurve("", pplRay1, Color.White, SymbolType.None);
            LineItem litRay2 = zedPolar.GraphPane.AddCurve("", pplRay2, Color.White, SymbolType.None);
            LineItem litRay3 = zedPolar.GraphPane.AddCurve("", pplRay3, Color.White, SymbolType.None);
            LineItem litRay4 = zedPolar.GraphPane.AddCurve("", pplRay4, Color.White, SymbolType.None);
            LineItem litRay5 = zedPolar.GraphPane.AddCurve("", pplRay5, Color.White, SymbolType.None);
            LineItem litRay6 = zedPolar.GraphPane.AddCurve("", pplRay6, Color.White, SymbolType.None);
            LineItem litRay7 = zedPolar.GraphPane.AddCurve("", pplRay7, Color.White, SymbolType.None);
            LineItem litRay8 = zedPolar.GraphPane.AddCurve("", pplRay8, Color.White, SymbolType.None);
            LineItem litRay9 = zedPolar.GraphPane.AddCurve("", pplRay9, Color.White, SymbolType.None);
            LineItem litRay10 = zedPolar.GraphPane.AddCurve("", pplRay10, Color.White, SymbolType.None);
            LineItem litRay11 = zedPolar.GraphPane.AddCurve("", pplRay11, Color.White, SymbolType.None);
            LineItem litRay12 = zedPolar.GraphPane.AddCurve("", pplRay12, Color.White, SymbolType.None);
            LineItem litRay13 = zedPolar.GraphPane.AddCurve("", pplRay13, Color.White, SymbolType.None);
            LineItem litRay14 = zedPolar.GraphPane.AddCurve("", pplRay14, Color.White, SymbolType.None);
            LineItem litRay15 = zedPolar.GraphPane.AddCurve("", pplRay15, Color.White, SymbolType.None);
            LineItem litRay16 = zedPolar.GraphPane.AddCurve("", pplRay16, Color.White, SymbolType.None);
            LineItem litRay17 = zedPolar.GraphPane.AddCurve("", pplRay17, Color.White, SymbolType.None);
            LineItem litRay18 = zedPolar.GraphPane.AddCurve("", pplRay18, Color.White, SymbolType.None);
            LineItem litRay19 = zedPolar.GraphPane.AddCurve("", pplRay19, Color.White, SymbolType.None);

            #endregion

            #region 加刻度

            TextObj txt0 = new TextObj("-90", 4 * step + 100, 0 + 10, CoordType.AxisXYScale, AlignH.Left, AlignV.Top);
            TextObj txt1 = new TextObj("90", -4 * step - 80, 0 + 10, CoordType.AxisXYScale, AlignH.Right, AlignV.Top);
            TextObj txt2 = new TextObj("0", 0, 5 * step + 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            TextObj txt3 = new TextObj("-15", intersection[0, 0], intersection[0, 1] + 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            TextObj txt4 = new TextObj("-30", intersection[1, 0], intersection[1, 1] + 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            TextObj txt5 = new TextObj("-45", intersection[2, 0] + 100, intersection[2, 1] + 20, CoordType.AxisXYScale, AlignH.Left, AlignV.Top);
            TextObj txt6 = new TextObj("-60", intersection[3, 0] + 100, intersection[3, 1] + 20, CoordType.AxisXYScale, AlignH.Left, AlignV.Top);
            TextObj txt7 = new TextObj("-75", intersection[4, 0] + 100, intersection[4, 1] + 20, CoordType.AxisXYScale, AlignH.Left, AlignV.Top);
            TextObj txt8 = new TextObj("15", intersection[5, 0], intersection[5, 1] + 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            TextObj txt9 = new TextObj("30", intersection[6, 0], intersection[6, 1] + 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            TextObj txt10 = new TextObj("45", intersection[7, 0] - 80, intersection[7, 1] + 20, CoordType.AxisXYScale, AlignH.Right, AlignV.Top);
            TextObj txt11 = new TextObj("60", intersection[8, 0] - 80, intersection[8, 1] + 20, CoordType.AxisXYScale, AlignH.Right, AlignV.Top);
            TextObj txt12 = new TextObj("75", intersection[9, 0] - 80, intersection[9, 1] + 20, CoordType.AxisXYScale, AlignH.Right, AlignV.Top);
            TextObj txt13 = new TextObj("-105", intersection[10, 0] + 80, intersection[10, 1] - 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom);
            TextObj txt14 = new TextObj("-120", intersection[11, 0] + 80, intersection[11, 1] - 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom);
            TextObj txt15 = new TextObj("105", intersection[12, 0] - 60, intersection[12, 1] - 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom);
            TextObj txt16 = new TextObj("120", intersection[13, 0] - 60, intersection[13, 1] - 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom);
            TextObj txt17 = new TextObj("135", intersection[7, 0] - 60, -1 * (intersection[7, 1] + 20), CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom);
            TextObj txt18 = new TextObj("-135", -1 * (intersection[7, 0] - 80), -1 * (intersection[7, 1] + 20), CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom);
            TextObj txt19 = new TextObj("-150", intersection[1, 0] - 60, -1 * (intersection[1, 1] + 140), CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            TextObj txt20 = new TextObj("150", -1 * (intersection[1, 0]), -1 * (intersection[1, 1] + 140), CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            TextObj txt21 = new TextObj("-165", intersection[0, 0], -1 * (intersection[0, 1] + 140), CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            TextObj txt22 = new TextObj("165", intersection[5, 0], -1 * (intersection[5, 1] + 140), CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            TextObj txt23 = new TextObj("180", 0, -1 * (5 * step + 140), CoordType.AxisXYScale, AlignH.Center, AlignV.Top);

            txt0.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt0.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt0.FontSpec.FontColor = Color.White;
            txt1.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt1.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt1.FontSpec.FontColor = Color.White;
            txt2.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt2.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt2.FontSpec.FontColor = Color.White;
            txt3.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt3.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt3.FontSpec.FontColor = Color.White;
            txt4.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt4.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt4.FontSpec.FontColor = Color.White;
            txt5.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt5.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt5.FontSpec.FontColor = Color.White;
            txt6.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt6.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt6.FontSpec.FontColor = Color.White;
            txt7.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt7.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt7.FontSpec.FontColor = Color.White;
            txt8.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt8.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt8.FontSpec.FontColor = Color.White;
            txt9.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt9.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt9.FontSpec.FontColor = Color.White;
            txt10.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt10.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt10.FontSpec.FontColor = Color.White;
            txt11.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt11.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt11.FontSpec.FontColor = Color.White;
            txt12.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt12.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt12.FontSpec.FontColor = Color.White;
            txt13.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt13.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt13.FontSpec.FontColor = Color.White;
            txt14.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt14.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt14.FontSpec.FontColor = Color.White;
            txt15.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt15.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt15.FontSpec.FontColor = Color.White;
            txt16.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt16.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt16.FontSpec.FontColor = Color.White;
            txt17.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt17.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt17.FontSpec.FontColor = Color.White;
            txt18.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt18.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt18.FontSpec.FontColor = Color.White;
            txt19.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt19.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt19.FontSpec.FontColor = Color.White;
            txt20.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt20.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt20.FontSpec.FontColor = Color.White;
            txt21.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt21.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt21.FontSpec.FontColor = Color.White;
            txt22.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt22.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt22.FontSpec.FontColor = Color.White;
            txt23.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txt23.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt23.FontSpec.FontColor = Color.White;

            zedPolar.GraphPane.GraphObjList.Add(txt0);
            zedPolar.GraphPane.GraphObjList.Add(txt1);
            zedPolar.GraphPane.GraphObjList.Add(txt2);
            zedPolar.GraphPane.GraphObjList.Add(txt3);
            zedPolar.GraphPane.GraphObjList.Add(txt4);
            zedPolar.GraphPane.GraphObjList.Add(txt5);
            zedPolar.GraphPane.GraphObjList.Add(txt6);
            zedPolar.GraphPane.GraphObjList.Add(txt7);
            zedPolar.GraphPane.GraphObjList.Add(txt8);
            zedPolar.GraphPane.GraphObjList.Add(txt9);
            zedPolar.GraphPane.GraphObjList.Add(txt10);
            zedPolar.GraphPane.GraphObjList.Add(txt11);
            zedPolar.GraphPane.GraphObjList.Add(txt12);
            zedPolar.GraphPane.GraphObjList.Add(txt13);
            zedPolar.GraphPane.GraphObjList.Add(txt14);
            zedPolar.GraphPane.GraphObjList.Add(txt15);
            zedPolar.GraphPane.GraphObjList.Add(txt16);
            zedPolar.GraphPane.GraphObjList.Add(txt17);
            zedPolar.GraphPane.GraphObjList.Add(txt18);
            zedPolar.GraphPane.GraphObjList.Add(txt19);
            zedPolar.GraphPane.GraphObjList.Add(txt20);
            zedPolar.GraphPane.GraphObjList.Add(txt21);
            zedPolar.GraphPane.GraphObjList.Add(txt22);
            zedPolar.GraphPane.GraphObjList.Add(txt23);

            #endregion
        }

        private double[,] angToReg(double gammaSample, double gammaRange, double[] data)
        {
            double[,] reg = new double[2, data.Length];

            int i = 0;

            foreach (double value in data)
            {
                double degree = Math.PI * (-gammaRange + i * gammaSample + 90) / 180;
                double length = (value - yMin) * 1000 / (yMax - yMin);
                reg[0, i] = length * Math.Cos(degree);
                reg[1, i] = length * Math.Sin(degree);
                i++;
            }

            return reg;
        }

        private void setAxsi()
        {
            if (yMin >= yMax || yMin < 0 || yMax <= 0)
            {
                return;
            }

            TextObj txtStepMin = new TextObj(yMin.ToString("#0"), 0, 0 + 10, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);

            txtStepMin.FontSpec.FontColor = Color.White;
            txtStepMin.FontSpec.Border = new Border(false, Color.Black, 0.1f);
            txtStepMin.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);

            if (zedPolar.GraphPane.GraphObjList.Count < 25)
            {
                zedPolar.GraphPane.GraphObjList.Add(txtStepMin);
            }
            else
            {
                zedPolar.GraphPane.GraphObjList[24] = txtStepMin;
            }

            for (int i = 1; i < 5; i++)
            {
                TextObj txtStep = new TextObj((yMin + (yMax - yMin) * i / 4).ToString("#0"), 0, i * step, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
                txtStep.FontSpec.Border = new Border(false, Color.Black, 0.1f);
                txtStep.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
                txtStep.FontSpec.FontColor = Color.White;

                if (zedPolar.GraphPane.GraphObjList.Count < 25 + i)
                {
                    zedPolar.GraphPane.GraphObjList.Add(txtStep);
                }
                else
                {
                    zedPolar.GraphPane.GraphObjList[24 + i] = txtStep;
                }
            }

            zedPolar.Refresh();
        }

        public void Display()
        {
            lux2DData[(int)thetaDegree / 15] = luxData;

            for (int i = 0; i < 12; i++)
            {
                if (lux2DData[i] != null)
                {
                    if (yMin > lux2DData[i].Min())
                    {
                        yMin = lux2DData[i].Min();
                    }
                    if (yMax < lux2DData[i].Max())
                    {
                        yMax = lux2DData[i].Max();
                    }
                }
            }

            for (int i = 0; i < 12; i++)
            {
                pplData[i].Clear();

                if (lux2DData[i] != null)
                {
                    if (lux2DData[i].Max() != 0)
                    {
                        double[,] reg = angToReg(gammaSample, gammaRange, lux2DData[i]);

                        for (int j = 0; j < reg.Length / 2; j++)
                        {
                            pplData[i].Add(reg[0, j], reg[1, j]);
                        }

                        litData[i] = zedPolar.GraphPane.AddCurve("", pplData[i], lineColor[i], SymbolType.None);
                    }
                }
            }

            zedPolar.Refresh();
        }

        public void Clear()
        {
            for (int i = 0; i < pplData.Length; i++)
            {
                pplData[i].Clear();
            }

            zedPolar.Refresh();
        }

        #endregion

        #region 窗体事件

        private void frmL1_Load(object sender, EventArgs e)
        {
            initailize();
            setAxsi();
        }

        private void frmL1_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }

        #endregion

        #region 其它事件

        private void cmsSetAxsi_Click(object sender, EventArgs e)
        {
            frmSetAxsi frm_SetAxsi = new frmSetAxsi();

            frm_SetAxsi.YMin = yMin;
            frm_SetAxsi.YMax = yMax;

            frm_SetAxsi.ShowDialog();

            if (frm_SetAxsi.DialogResult == DialogResult.OK)
            {
                yMin = frm_SetAxsi.YMin;
                yMax = frm_SetAxsi.YMax;

                setAxsi();

                if (luxData != null)
                {
                    if (luxData.Max() > 0)
                    {
                        Display();
                    }
                }
            }
        }

        #endregion
    }
}
